package org.shinetour.sms.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static cn.hutool.core.util.StrUtil.isEmpty;

/**
 * @Description: 字符串相关处理
 * @Author: ZhenHua Wang
 * @CreateDate: 2020/4/1 15:34
 */

public class StringUtils {

    /**
     * @Description: 校验是否是手机号
     * @Author: ZhenHua Wang
     * @CreateDate: 2020/4/21 17:10
     */
    public static boolean isMobile(String str) {
        if (isEmpty(str) || str.length() != 11) {
            return false;
        }
        String patternStr = "^((13[0-9])|(14[5-9])|(15([0-3]|[5-9]))|(16([2]|[5-7]))|(17[0-8])|(18[0-9])|(19([0-2]|[6-9])))\\d{8}$";
        Pattern pattern = Pattern.compile(patternStr);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }

    /**
     * @Description: 校验是否是座机号
     * @Author: ZhenHua Wang
     * @CreateDate: 2020/4/21 17:10
     */
    public static boolean isTel(String str) {
        if (isEmpty(str)) {
            return false;
        }
        String patternStr = "^0\\d{2,3}-\\d{7,8}$";
        Pattern pattern = Pattern.compile(patternStr);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }
}
